<?php

namespace util;

class WsMsgTool
{
    /**
     * ws消息
     * @param $type
     * @param array $content
     */
    public static function sendMsg($type, array $content = [])
    {
        $client = stream_socket_client('ws://ws地址');
        if (!$client) {
            return;
        }
        $data['type'] = $type;
        /**...**/
        $data['data'] = $content;
        // 模拟超级用户，以文本协议发送数据，注意Text文本协议末尾有换行符
        fwrite($client, json_encode($data) . "\n");
        fclose($client);
    }
}